<template>
  <ul class="switches">
    <li
      class="switches-item"
      v-for="(item, index) in switches"
      :key="index"
      :class="{'active': currentIndex === index}"
      @click="selectItem(index)"
      >
      {{item}}
    </li>
  </ul>
</template>

<script>
export default {
  name: 'switches',
  props: {
    switches: {
      type: Array,
      default () {
        return []
      }
    },
    currentIndex: {
      type: Number,
      default: 0
    }
  },
  methods: {
    selectItem (index) {
      this.$emit('switch', index)
    }
  }
}
</script>

<style lang="stylus" scoped>
  @import '~common/stylus/variable.styl'
  .switches {
    overflow: hidden
    display: flex
    margin: 0 auto
    width: 60%
    text-align: center
    line-height: 28px
    border: 1px solid $color-highlight-background
    border-radius: 6px
    .switches-item {
      flex: 1
      color: $color-text-l
      font-size: $font-size-small
      &.active {
        background: $color-highlight-background
        color: $color-text
      }
    }
  }
</style>
